package com.framework.modules.finance;

import com.framework.exception.util.RespResult;
import com.framework.modules.sys.controller.AbstractController;
import com.framework.page.PageUtils;
import com.framework.service.BenefitDayService;
import com.framework.service.BenefitInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 分润相关
 * @author wq
 */
@RestController
@RequestMapping("/sys/benefit")
public class BenefitController extends AbstractController {

    @Autowired
    private BenefitDayService benefitDayService;
    @Autowired
    private BenefitInfoService benefitInfoService;

    @RequestMapping("/list")
    @RequiresPermissions("sys:benifit:list")
    public RespResult queryListByAgentId(@RequestParam Map<String,Object> params){
        params.put("deptId",getUser().getDeptId());
        PageUtils page=benefitDayService.queryListByAgentId(params);
        return RespResult.ok().put("page",page);
    }

    @RequestMapping("/detail")
    @RequiresPermissions("sys:benifit:list")
    public  RespResult queryDetail( @RequestParam Map<String,Object> params){
        params.put("deptId",getUser().getDeptId());
        PageUtils page=benefitInfoService.queryDetailByBenefitId(params);
        return RespResult.ok().put("page",page);
    }

    /**
     * 下载
     * @param response
     */
    @RequestMapping("/downLoad")
    public  void downLoad(HttpServletResponse response){
        benefitDayService.downLoad(getDeptId(),response);
    }


    @RequestMapping("/countTotal")
    public RespResult countTotal(@RequestBody Map<String,Object> q){
        q.put("deptId",getUser().getDeptId());
        Map<String,Object> map=benefitDayService.countTotal(q);
        return RespResult.ok(map);
    }

}
